:root {
  --green: #1f3d2b;
  --green-2: #2e5a3f;
  --magenta: #c2187a;
  --warn: #f5a400;
  --bg: #fff;
  --text: #1b1b1b;
  --muted: #666;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--text); }
#map { position: fixed; inset: 0; background: #ddd; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
button { font: inherit; cursor: pointer; border-radius: 8px; border: 1px solid #ccc; background: #f4f4f4; padding: 8px 12px; color: var(--text); }
button.primary { background: var(--green); border-color: var(--green); color: #fff; font-weight: 600; }
button.danger, .menu-item.danger { color: #b00020; }
input { font: inherit; padding: 10px; border: 1px solid #bbb; border-radius: 8px; width: 100%; }

/* Top bar */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
  display: flex; align-items: center; gap: 8px;
  padding: calc(6px + var(--safe-top)) 10px 6px;
  background: var(--green); color: #fff; font-size: 15px;
}
#topbar .spacer { flex: 1; }
#topbar .muted { color: #cfe3d4; }
.icon-btn { background: transparent; border: none; color: inherit; font-size: 20px; padding: 4px 8px; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: #c33; flex: none; }
.dot.ok { background: #4caf50; }
.dot.wait { background: var(--warn); }

#edit-banner {
  position: fixed; top: calc(44px + var(--safe-top)); left: 0; right: 0; z-index: 999;
  background: var(--magenta); color: #fff; padding: 8px 12px; font-size: 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
#edit-banner button { background: #fff; color: var(--magenta); border: none; font-weight: 600; }

/* Leaflet control offsets for top bar */
.leaflet-top { top: calc(44px + var(--safe-top)); }
body.editing .leaflet-top { top: calc(84px + var(--safe-top)); }
.leaflet-bottom { bottom: calc(64px + var(--safe-bottom)); }

/* Floating buttons */
#fabs { position: fixed; right: 10px; bottom: calc(80px + var(--safe-bottom)); z-index: 1000; display: flex; flex-direction: column; gap: 10px; }
.fab { width: 48px; height: 48px; border-radius: 50%; font-size: 22px; padding: 0; background: #fff; border: none; box-shadow: 0 2px 6px rgba(0,0,0,.35); }
.fab.warn { background: var(--warn); }
.fab.active { background: var(--green-2); color: #fff; }

/* Info bar */
#infobar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000;
  background: rgba(255,255,255,.96); padding: 8px 12px calc(8px + var(--safe-bottom));
  box-shadow: 0 -2px 6px rgba(0,0,0,.2); font-size: 15px;
}
#info-target { margin-top: 4px; font-weight: 600; color: var(--magenta); display: flex; align-items: center; gap: 8px; }
#info-target .arrow { display: inline-block; font-size: 20px; }

/* Panels */
.panel {
  position: fixed; top: calc(44px + var(--safe-top)); right: 0; bottom: 0; width: min(340px, 90vw);
  z-index: 1100; background: var(--bg); box-shadow: -2px 0 10px rgba(0,0,0,.3);
  padding: 10px 12px calc(10px + var(--safe-bottom)); overflow-y: auto;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.panel .close { color: var(--text); }
.menu-item { display: block; width: 100%; text-align: left; margin: 6px 0; background: #f6f6f6; }
.file-label { padding: 8px 12px; border: 1px solid #ccc; border-radius: 8px; cursor: pointer; }
.row { display: flex; gap: 8px; align-items: center; }
.row.end { justify-content: flex-end; }
#search-form { margin-bottom: 8px; }

#leaders-list { list-style: none; padding: 0; margin: 0; }
#leaders-list li { display: flex; align-items: center; gap: 10px; padding: 10px 4px; border-bottom: 1px solid #eee; cursor: pointer; }
#leaders-list .swatch { width: 16px; height: 16px; border-radius: 50%; flex: none; border: 2px solid #fff; box-shadow: 0 0 0 1px #999; }
#leaders-list .grow { flex: 1; min-width: 0; }
#leaders-list .sub { font-size: 12px; color: var(--muted); }
#leaders-list .offline { opacity: .55; }
#leaders-list button { padding: 4px 8px; font-size: 12px; }
#leaders-list .icon { padding: 4px 6px; background: transparent; border-color: transparent; font-size: 16px; }
#leaders-list .label-tag { font-weight: normal; color: var(--muted); }
#leaders-list li.is-hidden .grow, #leaders-list li.is-hidden .swatch { opacity: .45; }
#leaders-list .hidden-tag { font-size: 11px; background: #eee; border-radius: 6px; padding: 0 5px; margin-left: 4px; color: var(--muted); }
.panel-actions { flex-wrap: wrap; margin: 6px 0; }
#hidden-note {
  position: fixed; top: calc(52px + var(--safe-top)); left: 50%; transform: translateX(-50%); z-index: 1000;
  background: rgba(0,0,0,.7); color: #fff; border: none; border-radius: 14px; padding: 4px 12px; font-size: 13px;
}
body.editing #hidden-note { top: calc(92px + var(--safe-top)); }

/* Modals */
.modal { position: fixed; inset: 0; z-index: 2000; background: rgba(15,30,20,.75); display: flex; align-items: center; justify-content: center; padding: 16px; }
.card { background: #fff; border-radius: 14px; padding: 18px; width: min(420px, 100%); max-height: 100%; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.card h1 { margin: 0; font-size: 24px; color: var(--green); }
.card h2 { margin: 0; font-size: 18px; }
.card label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 14px; }
.card .label { font-weight: 600; font-size: 14px; }
.card label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: normal; }
.card label.check input { width: auto; }
#swatches { display: flex; flex-wrap: wrap; gap: 8px; }
#swatches button { width: 36px; height: 36px; border-radius: 50%; padding: 0; border: 3px solid #fff; box-shadow: 0 0 0 1px #aaa; }
#swatches button.sel { box-shadow: 0 0 0 3px var(--text); }
#swatches button.taken {
  opacity: .3; cursor: not-allowed;
  background-image: linear-gradient(45deg, transparent 45%, #000 45%, #000 55%, transparent 55%) !important;
}
#colour-section { display: flex; flex-direction: column; gap: 8px; }
.error { color: #b00020; font-weight: 600; margin: 0; font-size: 14px; }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(90px + var(--safe-bottom));
  z-index: 3000; background: rgba(0,0,0,.85); color: #fff; padding: 10px 16px; border-radius: 20px; font-size: 14px; max-width: 90vw; text-align: center;
}

/* Map icons */
.cp-icon { background: none; border: none; }
.cp {
  width: 34px; height: 34px; border-radius: 50%;
  border: 4px solid var(--magenta); background: rgba(255,255,255,.85);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 14px; color: var(--magenta);
  box-shadow: 0 0 0 1px #fff, 0 1px 4px rgba(0,0,0,.5);
}
.cp.target { background: var(--magenta); color: #fff; }
.editing .cp { border-style: dashed; }

.leader-icon { background: none; border: none; }
.leader { position: relative; width: 22px; height: 22px; }
.leader .pin { width: 22px; height: 22px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 1px 5px rgba(0,0,0,.6); }
.leader .name {
  position: absolute; left: 26px; top: 1px; white-space: nowrap;
  background: rgba(0,0,0,.7); color: #fff; font-size: 12px; font-weight: 600; padding: 1px 6px; border-radius: 8px;
}
.leader.me .pin { box-shadow: 0 0 0 4px rgba(255,255,255,.6), 0 1px 5px rgba(0,0,0,.6); }
.leader.stale { opacity: .5; }
.leader.stale .pin { filter: grayscale(.7); }


.leaflet-popup-content { font-size: 14px; }

/* Messages */
.fab { position: relative; }
.badge {
  position: absolute; top: -4px; right: -4px; min-width: 20px; height: 20px; padding: 0 5px;
  border-radius: 10px; background: #d32f2f; color: #fff; font-size: 12px; font-weight: 700; line-height: 20px;
}
.compose { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; padding-bottom: 12px; border-bottom: 1px solid #ddd; }
.compose label { display: flex; flex-direction: column; gap: 3px; font-size: 13px; font-weight: 600; }
.recipients { border: 1px solid #ccc; border-radius: 8px; padding: 6px 10px 8px; margin: 0; max-height: 190px; overflow-y: auto; }
.recipients legend { font-size: 13px; font-weight: 600; padding: 0 4px; }
.compose .recipients label { flex-direction: row; align-items: center; gap: 8px; font-weight: normal; font-size: 14px; padding: 3px 0; }
.recipients input { width: auto; margin: 0; }
.recipients .offline { color: var(--muted); }
select, textarea { font: inherit; padding: 9px; border: 1px solid #bbb; border-radius: 8px; width: 100%; background: #fff; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { padding: 5px 10px; font-size: 13px; border-radius: 14px; background: #eef4ef; border-color: #b9d3bf; }
.row.between { justify-content: space-between; }
.small-btn { padding: 3px 8px; font-size: 12px; }
#msg-list { list-style: none; padding: 0; margin: 6px 0 0; }
#msg-list li { padding: 8px 4px; border-bottom: 1px solid #eee; font-size: 14px; }
#msg-list .meta { font-size: 12px; color: var(--muted); }
#msg-list .text { margin: 3px 0; font-weight: 600; }
#msg-list .acks { font-size: 12px; }
#msg-list .acks .ok { color: #2e7d32; }
#msg-list .acks .wait { color: #c62828; }
#msg-list li.mine { background: #f7fbf8; }
#msg-list li.unread .text { color: #c62828; }
.incoming-card { text-align: center; gap: 14px; }
#incoming-from { font-size: 15px; }
#incoming-text { font-size: 28px; font-weight: 800; line-height: 1.2; word-wrap: break-word; }
#incoming-point { font-size: 18px; font-weight: 700; color: var(--magenta); }
button.big { padding: 14px; font-size: 18px; }
#incoming { background: rgba(120, 10, 10, .85); }
.popup-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.popup-actions button { padding: 6px 10px; font-size: 13px; }
.version-label { margin: 0; text-align: center; }
a.menu-item { color: var(--text); text-decoration: none; box-sizing: border-box; padding: 8px 12px; border: 1px solid #ccc; border-radius: 8px; }
.join-help { margin: 0; text-align: center; }
.join-help a { color: var(--green-2); }
.version-label a { color: #b00020; font-weight: 600; }

/* Roles, PINs and game settings */
.roles { border: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.roles .label { padding: 0; margin-bottom: 2px; }
.card .roles label.check { font-size: 15px; }
.settings-block { display: flex; flex-direction: column; gap: 8px; padding: 12px 0; border-bottom: 1px solid #eee; }
.pin-row { display: flex; flex-direction: column; gap: 6px; padding: 6px 0; }
.pin-status { font-size: 13px; color: var(--muted); }
.pin-status.on { color: #2e7d32; font-weight: 600; }
body:not(.is-base) .base-only { display: none !important; }
.version-label a.whats-new-link { color: var(--green-2); }

/* Rounds */
.round-label { background: rgba(255,255,255,.15); border-radius: 10px; padding: 1px 8px; font-size: 13px; white-space: nowrap; }
.round-label.overtime { background: var(--warn); color: #000; }
.round-status { margin: 0; font-weight: 600; }
.row.wrap { flex-wrap: wrap; }
.row .grow { flex: 1; }
#round-start-form { align-items: flex-end; }
#timings-form label { display: flex; flex-direction: column; gap: 3px; font-size: 14px; }
.game-over-card { text-align: center; }
.big-emoji { font-size: 56px; line-height: 1; }
#game-over { background: rgba(15,30,20,.88); z-index: 2500; }
/* Leaders quiet for a while: smaller and greyer */
.leader.old .pin { width: 14px; height: 14px; margin: 4px; filter: grayscale(1); }
.leader.old .name { opacity: .8; font-weight: 500; }
/* Keep the top bar on one line: the game name gives way (with "…"), counts and timer don't. */
#topbar { flex-wrap: nowrap; min-height: calc(44px + var(--safe-top)); }
#room-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 0 1 auto; }
#online-label, .round-label { white-space: nowrap; flex: none; font-size: 13px; }
@media (max-width: 380px) { #online-label { display: none; } }
/* Patrols */
body.is-patrol .not-patrol { display: none !important; }
body.is-patrol #online-label { display: none; }
.leader.patrol .pin { border-radius: 4px; }
.leader.patrol .name::before { content: "🔦 "; }
#leaders-list li.group { cursor: default; font-weight: 700; font-size: 13px; color: var(--muted); padding: 10px 4px 4px; border-bottom: none; }
#visibility-block label.check { display: flex; flex-direction: row; gap: 8px; align-items: center; font-size: 14px; font-weight: normal; }
#visibility-block label.check input { width: auto; }

/* Joining with an invite, and base's QR codes (v1.7) */
.invite-intro { margin: 0; font-size: 16px; background: #eef4ef; border-left: 4px solid var(--green-2); padding: 8px 12px; border-radius: 6px; }
#base-extras { display: flex; flex-direction: column; gap: 6px; }
.join-invite-note { margin: 0; }
.invite-card { gap: 10px; }
.invite-qr { background: #fff; display: flex; justify-content: center; align-items: center; min-height: 200px; }
.invite-qr svg { width: min(78vw, 320px); height: auto; display: block; }
#invite-text, #invite-note, #invite-joined { margin: 0; }
#base-setup .card { gap: 10px; }

/* 🥾 Footpaths button (v1.8) */
.paths-control .paths-btn { font-size: 20px; width: 44px; height: 44px; line-height: 44px; text-align: center; background: #fff; opacity: .6; filter: grayscale(1); }
.paths-control .paths-btn.on { opacity: 1; filter: none; background: #fff6c2; }
.paths-control .paths-btn.loading { opacity: 1; filter: none; animation: paths-pulse 1s ease-in-out infinite alternate; }
@keyframes paths-pulse { from { background: #fff; } to { background: #ffd400; } }

/* "Your games" on the join screen (v1.9) */
#your-games { display: flex; flex-direction: column; gap: 6px; }
#your-games-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; max-height: 180px; overflow-y: auto; }
#your-games-list li { display: flex; gap: 6px; align-items: stretch; }
#your-games-list .game-pick { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; text-align: left; gap: 2px; background: #eef4ef; border-color: #cfe0d3; }
#your-games-list .game-pick strong { overflow-wrap: anywhere; }
#your-games-list .game-forget { flex: none; padding: 0 12px; }

/* 🧭 Set-up guide (v1.9): a sheet at the bottom, map in view above */
#setup-guide.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1500; max-height: 58vh; overflow-y: auto;
  background: #fff; border-radius: 16px 16px 0 0; box-shadow: 0 -4px 16px rgba(0,0,0,.3);
  padding: 12px 16px calc(14px + var(--safe-bottom)); display: flex; flex-direction: column; gap: 8px;
}
#setup-guide h2 { margin: 0; font-size: 19px; color: var(--green); }
#guide-body { display: flex; flex-direction: column; gap: 8px; }
#guide-body p { margin: 0; }
#guide-body > button { text-align: left; }
.guide-search input { flex: 1; min-width: 0; }
#guide-results { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
#guide-results .guide-result { width: 100%; text-align: left; font-size: 14px; }
#guide-copy summary { cursor: pointer; padding: 8px 0; font-weight: 600; }
#guide-copy form { display: flex; flex-direction: column; gap: 8px; }
#guide-copy label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 14px; }
.guide-status { background: #eef4ef; border-radius: 8px; padding: 6px 10px; }
.guide-nav { margin-top: 4px; }
#guide-next { margin-left: auto; }
