:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --ink: #2b2118;
  --muted: #7a6d60;
  --line: #e6ded3;
  --coffee: #8a4b24;
  --coffee-soft: #f3e6da;
  --route: #e8590c;
  --mine: #2f9e44;
  --closed: #a8a29e;
  --shadow: 0 6px 24px rgba(43, 33, 24, .14);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

/* Header */
.bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
  z-index: 1001;
}
.title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.emoji { font-size: 22px; }
h1 { font-size: 16px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#stats { margin: 0; color: var(--muted); font-size: 13px; }
.controls { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.toggle { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 4px; cursor: pointer; }
.toggle input { accent-color: var(--route); }
button { font: inherit; cursor: pointer; }
.who {
  border: 1px solid var(--line); background: var(--coffee-soft); color: var(--coffee);
  border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 600;
}

/* Layout */
main { flex: 1; display: flex; min-height: 0; position: relative; }
#map { flex: 1; min-height: 0; }
.panel {
  width: 340px; background: var(--surface); border-left: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}
.handle {
  display: flex; justify-content: space-between; align-items: center;
  border: 0; border-bottom: 1px solid var(--line); background: none;
  padding: 14px 16px; font-weight: 700; font-size: 15px; text-align: left; color: var(--ink);
  cursor: default;
}
.pill { background: var(--mine); color: #fff; border-radius: 999px; padding: 2px 9px; font-size: 12px; }
.pill:empty { display: none; }
.panel-body { overflow-y: auto; padding: 12px 16px 20px; }
.hint { margin: 0 0 12px; color: var(--muted); font-size: 13px; }
.intro { margin-bottom: 12px; }
.intro summary { cursor: pointer; font-weight: 600; font-size: 13px; color: var(--coffee); margin-bottom: 8px; }
.intro:not([open]) summary { margin-bottom: 0; }
.notice { background: #fff4e6; border: 1px solid #ffd8a8; border-radius: 8px; padding: 8px 10px; font-size: 13px; margin-bottom: 12px; }

/* Leaderboard */
.board { list-style: none; margin: 0; padding: 0; }
.board li {
  display: grid; grid-template-columns: 22px 1fr auto; gap: 8px; align-items: center;
  padding: 7px 6px; border-radius: 8px; cursor: pointer;
}
.board li:hover { background: var(--coffee-soft); }
.board .rank { color: var(--muted); font-size: 12px; text-align: right; }
.board .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .barwrap { grid-column: 2 / 3; height: 5px; background: var(--line); border-radius: 3px; overflow: hidden; }
.board .barfill { height: 100%; background: var(--coffee); border-radius: 3px; }
.board li.mine .barfill { background: var(--mine); }
.board .count { font-variant-numeric: tabular-nums; font-weight: 700; grid-row: 1 / 3; grid-column: 3; }
.board li.cutline { border-top: 2px dashed var(--line); margin-top: 6px; padding-top: 10px; }
.board .empty { color: var(--muted); cursor: default; display: block; }
.unvoted { margin-top: 14px; font-size: 13px; color: var(--muted); }
.unvoted ul { padding-left: 18px; columns: 2; margin: 8px 0 0; }
.unvoted li { cursor: pointer; break-inside: avoid; }
.unvoted li:hover { color: var(--coffee); }
.legend { margin-top: 16px; font-size: 12px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-right: -6px; }
.dot.open { background: var(--coffee); }
.dot.closed { background: transparent; border: 2px solid var(--closed); }
.dot.mine { background: var(--mine); }

/* Shop card (top of the side panel; inside the bottom sheet on phones) */
.card {
  padding: 14px 16px; border-bottom: 1px solid var(--line);
  background: var(--coffee-soft); border-left: 4px solid var(--route);
}
.card[hidden] { display: none; }
.pop { position: relative; font-size: 14px; }
.card-close {
  position: absolute; top: -6px; right: -6px; border: 0; background: none;
  font-size: 22px; line-height: 1; color: var(--muted); padding: 4px 8px;
}
.card-close:hover { color: var(--ink); }
.pop h3 { margin: 0 28px 2px 0; font-size: 16px; }
.pop .addr { color: var(--muted); font-size: 12px; margin: 0 0 8px; }
.pop .closed-badge { display: inline-block; background: #eee; color: #57534e; border-radius: 4px; padding: 1px 6px; font-size: 11px; font-weight: 700; margin-left: 6px; vertical-align: middle; }
.pop .note { font-style: italic; margin: 0 0 8px; }
.pop .visits { list-style: none; padding: 0; margin: 0 0 10px; max-height: 130px; overflow-y: auto; font-size: 13px; }
.pop .visits li { padding: 3px 0; border-top: 1px solid var(--line); }
.pop .visits a { color: var(--route); }
.vote-row { display: flex; align-items: center; gap: 10px; }
.vote-btn {
  border: 2px solid var(--coffee); background: #fff; color: var(--coffee);
  border-radius: 999px; padding: 6px 14px; font-weight: 700; font-size: 14px;
}
.vote-btn.on { background: var(--mine); border-color: var(--mine); color: #fff; }
.vote-btn:disabled { opacity: .6; cursor: wait; }
.voters { font-size: 12px; color: var(--muted); }
.closed-msg { font-size: 13px; color: var(--muted); margin: 0; }

/* Name dialog */
dialog { border: 0; border-radius: 14px; box-shadow: var(--shadow); padding: 20px; width: min(360px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(43, 33, 24, .35); }
dialog h2 { margin: 0 0 6px; font-size: 18px; }
dialog p { margin: 0 0 12px; color: var(--muted); font-size: 14px; }
dialog input { width: 100%; font: inherit; font-size: 16px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.actions button { border: 0; border-radius: 8px; padding: 8px 14px; font-weight: 600; background: var(--coffee); color: #fff; }
.actions button.secondary { background: var(--line); color: var(--ink); }

/* Phone: panel becomes a bottom sheet */
@media (max-width: 720px) {
  h1 { font-size: 14px; }
  .emoji { display: none; }
  .toggle { display: none; }
  .panel {
    position: absolute; left: 0; right: 0; bottom: 0; width: auto; z-index: 1000;
    border-left: 0; border-top: 1px solid var(--line); border-radius: 14px 14px 0 0;
    box-shadow: var(--shadow); max-height: 70%;
  }
  .handle { cursor: pointer; }
  .panel:not(.open) .panel-body { display: none; }
  .panel:not(.open) .handle { border-bottom: 0; }
  .leaflet-bottom { bottom: 56px; }
}
