:root {
  --bg: #111827;
  --card: #1f2937;
  --line: #374151;
  --text: #f9fafb;
  --muted: #9ca3af;
  --primary: #22c55e;
  --tracked: #ef4444;
  --hunter: #f59e0b;
  --spectator: #60a5fa;
  --danger: #dc2626;
  --sheet-h: 40vh;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.hidden { display: none !important; }
.screen { position: fixed; inset: 0; }

/* ---------- Accueil ---------- */
#home { display: flex; align-items: center; justify-content: center; padding: 16px; overflow: auto; }
.home-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 12px; }
.home-card h1 { margin: 0; font-size: 2.2rem; text-align: center; }
.subtitle { margin: 0 0 8px; color: var(--muted); text-align: center; }
.sep { text-align: center; color: var(--muted); }
label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: .9rem; }
input, select { font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; }
#codeInput { text-transform: uppercase; letter-spacing: .3em; text-align: center; font-weight: 700; }
.rules { color: var(--muted); font-size: .9rem; }
.rules summary { cursor: pointer; }
.error { color: #fca5a5; min-height: 1.2em; margin: 0; text-align: center; }

/* ---------- Boutons ---------- */
.btn { font: inherit; font-weight: 600; color: var(--text); background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; padding: 11px 14px; cursor: pointer; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #052e12; }
.btn.danger { background: var(--danger); border-color: var(--danger); }
.btn.warn { background: var(--hunter); border-color: var(--hunter); color: #3b2300; }
.btn.small { padding: 6px 10px; font-size: .85rem; }
.btn:disabled { opacity: .5; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row .btn { flex: 1 1 auto; }
.icon-btn { font-size: 1.2rem; background: var(--card); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; width: 40px; height: 40px; cursor: pointer; }
.icon-btn.round { border-radius: 50%; box-shadow: 0 2px 8px #0008; }

/* ---------- Écran de jeu ---------- */
#main { display: flex; flex-direction: column; }
#topbar { display: flex; align-items: center; gap: 8px; padding: 8px 10px; padding-top: max(8px, env(safe-area-inset-top));
  background: var(--bg); border-bottom: 1px solid var(--line); z-index: 1001; }
.top-left { display: flex; gap: 6px; }
.phase { flex: 1; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.badge { padding: 3px 8px; border-radius: 999px; font-size: .8rem; font-weight: 700; background: var(--card); border: 1px solid var(--line); }
.badge.tracked { background: var(--tracked); border-color: var(--tracked); }
.badge.hunter { background: var(--hunter); border-color: var(--hunter); color: #3b2300; }
.badge.spectator { background: var(--spectator); border-color: var(--spectator); color: #0b2447; }
.banner { padding: 10px; text-align: center; font-weight: 700; z-index: 1000; }
.banner.capture { background: var(--danger); }
.banner.pause { background: var(--spectator); color: #0b2447; }
.banner .btn-row { margin-top: 8px; justify-content: center; }
#map { flex: 1; min-height: 0; background: #e5e7eb; }
#mapButtons { position: absolute; right: 10px; bottom: calc(var(--sheet-h) + 12px); display: flex; flex-direction: column; gap: 8px; z-index: 1000; }
.gps-warn { position: absolute; left: 10px; right: 60px; bottom: calc(var(--sheet-h) + 12px); z-index: 1000;
  background: #7f1d1d; padding: 8px 10px; border-radius: 10px; font-size: .85rem; }

#sheet { height: var(--sheet-h); background: var(--bg); border-top: 1px solid var(--line); display: flex; flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom); z-index: 1001; transition: height .2s; }
#sheet.collapsed { height: 64px; }
#sheet.expanded { height: 78vh; }
#sheetHandle { padding: 6px 0; display: flex; justify-content: center; cursor: pointer; }
#sheetHandle span { width: 44px; height: 5px; border-radius: 3px; background: var(--line); }
#sheetContent { flex: 1; overflow: auto; padding: 0 12px 12px; display: flex; flex-direction: column; gap: 12px; }
#sheetContent h3 { margin: 4px 0 0; font-size: .95rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.big-info { font-size: 1.1rem; font-weight: 700; text-align: center; }
.muted { color: var(--muted); font-size: .9rem; }
.center { text-align: center; }

.players { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.players li { display: flex; align-items: center; gap: 8px; padding: 6px 8px; background: var(--card); border-radius: 10px; }
.players .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.players select { padding: 4px 6px; font-size: .85rem; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #6b7280; flex: none; }
.dot.on { background: var(--primary); }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
.check input { width: 20px; height: 20px; }

.points { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.points li { display: flex; align-items: center; gap: 6px; background: var(--card); padding: 6px 8px; border-radius: 10px; }
.points .num { font-weight: 800; width: 22px; text-align: center; }
.points input { flex: 1; min-width: 0; padding: 6px 8px; }

.progress { display: flex; gap: 6px; justify-content: center; }
.progress span { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line); display: flex; align-items: center; justify-content: center; font-size: .8rem; font-weight: 700; }
.progress span.done { background: var(--primary); border-color: var(--primary); color: #052e12; }
.progress span.cur { border-color: var(--primary); }

.winner { font-size: 1.6rem; font-weight: 800; text-align: center; padding: 8px; }

/* ---------- Modale ---------- */
.modal { position: fixed; inset: 0; background: #000a; z-index: 2000; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-card { background: var(--bg); border: 1px solid var(--line); border-radius: 14px; padding: 16px; width: 100%; max-width: 420px;
  max-height: 90vh; overflow: auto; display: flex; flex-direction: column; gap: 10px; }
.modal-card h2, .modal-card h3 { margin: 0; }
.log { list-style: none; margin: 0; padding: 0; font-size: .85rem; max-height: 35vh; overflow: auto; }
.log li { padding: 3px 0; border-bottom: 1px solid var(--line); }
.log time { color: var(--muted); margin-right: 6px; font-variant-numeric: tabular-nums; }

/* ---------- Toasts ---------- */
#toasts { position: fixed; top: 60px; left: 0; right: 0; z-index: 3000; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.toast { background: #000d; color: #fff; padding: 10px 14px; border-radius: 10px; max-width: 90%; font-weight: 600; animation: fade 4s forwards; }
@keyframes fade { 0% { opacity: 0; transform: translateY(-8px); } 8%, 85% { opacity: 1; transform: none; } 100% { opacity: 0; } }

/* ---------- Marqueurs carte ---------- */
.pin { width: 22px; height: 22px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 1px 4px #0009; }
.pin.me { background: #2563eb; }
.pin.hunter { background: var(--hunter); }
.pin.tracked { background: var(--tracked); }
.pin.spectator { background: var(--spectator); }
.pin.stale { opacity: .55; }
.pin-label { background: #000c; color: #fff; border: none; box-shadow: none; font-weight: 600; padding: 1px 5px; }
.pin-label::before { display: none; }
.obj-pin { width: 30px; height: 30px; border-radius: 50%; background: var(--primary); color: #052e12; border: 3px solid #fff;
  box-shadow: 0 1px 4px #0009; display: flex; align-items: center; justify-content: center; font-weight: 800; }
.obj-pin.done { background: #6b7280; color: #fff; }
.reveal-pin { width: 28px; height: 28px; border-radius: 50%; background: var(--tracked); border: 3px solid #fff;
  box-shadow: 0 0 0 6px #ef444466; display: flex; align-items: center; justify-content: center; font-size: 14px; }

/* ---------- Correctifs mise en page mobile ---------- */
#sheetContent { overflow-x: hidden; }
#sheetContent p { margin: 0; }
.grid > label, .grid input { min-width: 0; width: 100%; }
#sheetContent > label:not(.check) input { width: 100%; }
.check input { flex: none; width: 20px !important; }
#toasts { top: auto; bottom: calc(var(--sheet-h) + 64px); flex-direction: column-reverse; }
