:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #efebe4;
  --text: #1d1b19;
  --muted: #6c665e;
  --line: #e2ddd4;
  --line-strong: #cfc8bc;
  --accent: #e8542f;
  --accent-ink: #ffffff;
  --star: #e0a400;
  --clash: #d23c3c;
  --band: rgba(232, 84, 47, 0.10);
  --shadow: 0 6px 24px rgba(30, 20, 10, 0.16);

  --ppm: 1.8px;         /* pixels per minute */
  --col: 136px;         /* stage column width */
  --timecol: 52px;
  --head1: 30px;
  --head2: 24px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141312;
    --surface: #1e1c1a;
    --surface-2: #272522;
    --text: #f1ede7;
    --muted: #a39d94;
    --line: #2e2b28;
    --line-strong: #3d3935;
    --accent: #ff6b45;
    --star: #ffc53d;
    --clash: #ff6363;
    --band: rgba(255, 107, 69, 0.13);
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  }
}
:root[data-theme="dark"] {
  --bg: #141312; --surface: #1e1c1a; --surface-2: #272522; --text: #f1ede7; --muted: #a39d94;
  --line: #2e2b28; --line-strong: #3d3935; --accent: #ff6b45; --star: #ffc53d; --clash: #ff6363;
  --band: rgba(255, 107, 69, 0.13); --shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
}
@media (max-width: 640px) {
  :root { --col: 116px; --timecol: 44px; --ppm: 1.7px; }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  display: flex; flex-direction: column;
  height: 100vh; height: 100dvh; overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button { font: inherit; color: inherit; }

/* ---------- header ---------- */
.top {
  flex: none; position: relative; z-index: 50;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  padding: 10px 16px 8px;
}
.titlebar { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
h1 {
  font: 700 22px/1.1 "Space Grotesk", Inter, sans-serif;
  margin: 0; letter-spacing: -0.01em;
}
h1 span { color: var(--accent); }
.sub { margin: 0; color: var(--muted); font-size: 13px; }

.tabs { display: flex; gap: 6px; margin: 10px 0 8px; overflow-x: auto; scrollbar-width: none; }
.tab {
  border: 1px solid var(--line-strong); background: var(--surface);
  padding: 7px 14px; border-radius: 999px; cursor: pointer; white-space: nowrap;
  font-weight: 600;
}
.tab small { font-weight: 400; color: var(--muted); margin-left: 4px; }
.tab[aria-selected="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.tab[aria-selected="true"] small { color: inherit; opacity: .7; }

.toolbar { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line-strong); background: transparent; border-radius: 8px;
  padding: 4px 10px; cursor: pointer; font-size: 13px;
}
.chip[aria-pressed="true"] { background: var(--surface-2); border-color: var(--text); }
.chip b { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 3px; border-radius: 9px; background: var(--star); color: #1d1b19; font-size: 11px; text-align: center; }
.legend { display: flex; gap: 10px; flex-wrap: wrap; margin-left: 6px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
@media (max-width: 640px) {
  .legend, .sub { display: none; }
  .top { padding-top: 8px; }
  .tabs { margin: 8px 0 6px; }
}

/* ---------- map ---------- */
.mapPanel {
  flex: none; display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 0;
  border-bottom: 1px solid var(--line); background: var(--surface);
}
.mapPanel[hidden] { display: none; }
#map { height: 300px; background: var(--surface-2); isolation: isolate; z-index: 0; }
.venueList { margin: 0; padding: 8px 0; list-style: none; max-height: 300px; overflow: auto; font-size: 13px; border-left: 1px solid var(--line); }
.venueList li { display: flex; gap: 8px; align-items: flex-start; padding: 5px 12px; cursor: pointer; }
.venueList li:hover { background: var(--surface-2); }
.venueList .addr { color: var(--muted); font-size: 12px; }
.venueList a { color: var(--accent); font-size: 12px; white-space: nowrap; margin-left: auto; text-decoration: none; }
@media (max-width: 760px) {
  .mapPanel { grid-template-columns: 1fr; }
  #map { height: 200px; }
  .venueList { border-left: 0; border-top: 1px solid var(--line); max-height: 110px; padding: 4px 0; }
}
.pin {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink);
  font: 700 11px/22px Inter, sans-serif; text-align: center;
  border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.35);
}
.pin.off { background: #9a948b; opacity: .6; }
.num {
  flex: none; display: inline-block; width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink);
  font: 700 10px/18px Inter, sans-serif; text-align: center;
}
.leaflet-popup-content { font: 13px/1.4 Inter, sans-serif; }
.leaflet-popup-content a { color: var(--accent); }

/* ---------- plan ---------- */
/* grid and plan sit side by side; on phones the plan becomes a drawer over the grid */
.bodyRow { flex: 1 1 auto; min-height: 0; display: flex; }
.planPanel {
  flex: none; width: 340px; overflow: auto; padding: 10px 14px 16px;
  border-left: 1px solid var(--line-strong); background: var(--surface);
}
.planPanel[hidden] { display: none; }
@media (max-width: 760px) {
  .planPanel {
    position: fixed; z-index: 65; top: 0; right: 0; bottom: 0;
    width: min(360px, 90vw); box-shadow: var(--shadow);
    padding-top: max(10px, env(safe-area-inset-top));
  }
}
.planTitle { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 8px; }
.planTitle h2 { flex: 1; font: 700 16px/1.3 "Space Grotesk", Inter, sans-serif; margin: 2px 0 0; }
.planTitle .close { border: 0; background: transparent; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); width: 30px; height: 30px; flex: none; }
.planPanel ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.planPanel li {
  display: grid; grid-template-columns: 82px 1fr; column-gap: 8px; cursor: pointer;
  padding: 3px 6px; margin: 0 -6px; border-radius: 6px;
}
.planPanel li:hover { background: var(--surface-2); }
.planPanel .t { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; }
.planPanel .v { color: var(--muted); font-size: 12px; }
.planPanel .warn { grid-column: 2; color: var(--clash); font-size: 12px; font-weight: 600; }
.planPanel .empty { color: var(--muted); margin: 8px 0 0; font-size: 13px; }
.planHead { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.nameInput {
  font: inherit; font-size: 13px; color: var(--text); background: var(--bg);
  border: 1px solid var(--line-strong); border-radius: 8px; padding: 4px 8px; flex: 1; min-width: 0;
}
.shareBtn { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.shareBtn:disabled { opacity: .45; cursor: default; }
.chip.small { font-size: 12px; padding: 2px 8px; }
.friend { margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--line); }
.friendHead { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 4px; }
.friendHead .chip:first-of-type { margin-left: auto; }
.dot, .fr i {
  display: inline-block; border-radius: 50%; color: #fff; font-style: normal; text-align: center; font-weight: 700;
}
.dot { width: 20px; height: 20px; font-size: 9px; line-height: 20px; }
.fr { position: absolute; right: 4px; bottom: 3px; display: flex; gap: 2px; }
.fr i { width: 16px; height: 16px; font-size: 8px; line-height: 16px; box-shadow: 0 0 0 1.5px var(--surface); }
.set.tiny .fr { bottom: auto; top: 50%; transform: translateY(-50%); }
.set.tiny .fr i { width: 12px; height: 12px; line-height: 12px; font-size: 7px; }
.sheet .going { margin: 4px 0 0; }
.sheet .going span { font-weight: 600; }

.toast {
  position: fixed; z-index: 70; top: 14px; left: 50%; transform: translateX(-50%);
  max-width: calc(100vw - 32px); padding: 8px 14px; border-radius: 10px;
  background: var(--text); color: var(--bg); font-size: 13px; font-weight: 500; box-shadow: var(--shadow);
}

/* ---------- grid ---------- */
.gridWrap {
  flex: 1 1 auto; min-height: 0; min-width: 0;
  overflow: auto;
  position: relative;
  overscroll-behavior: contain;
}
.grid {
  display: grid;
  grid-template-rows: var(--head1) var(--head2) auto;
  width: max-content;
  min-width: 100%;
  position: relative;
}
.corner, .vhead, .shead { position: sticky; z-index: 20; background: var(--bg); }
.corner { left: 0; top: 0; z-index: 30; grid-row: 1 / 3; grid-column: 1; border-bottom: 1px solid var(--line-strong); border-right: 1px solid var(--line); }
.vhead {
  top: 0; grid-row: 1; padding: 6px 8px 0; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  border-left: 1px solid var(--line-strong);
  display: flex; align-items: center; gap: 6px;
}
.vhead a { text-decoration: none; overflow: hidden; text-overflow: ellipsis; }
.vhead a:hover { text-decoration: underline; }
.vhead .num { cursor: pointer; }
.shead {
  top: var(--head1); grid-row: 2; padding: 0 8px; font-size: 12px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  border-bottom: 1px solid var(--line-strong); border-left: 1px solid var(--line);
}
.shead.first { border-left-color: var(--line-strong); }

.times { grid-row: 3; grid-column: 1; position: sticky; left: 0; z-index: 15; background: var(--bg); border-right: 1px solid var(--line); }
.times span {
  position: absolute; right: 6px; transform: translateY(-50%);
  font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums;
}
.times span.h { color: var(--text); font-weight: 600; }

.col {
  grid-row: 3; position: relative; border-left: 1px solid var(--line);
  background-image:
    repeating-linear-gradient(to bottom, var(--line-strong) 0 1px, transparent 1px calc(var(--ppm) * 60)),
    repeating-linear-gradient(to bottom, var(--line) 0 1px, transparent 1px calc(var(--ppm) * 30));
}
.col.first { border-left-color: var(--line-strong); }

.overlay { grid-row: 3; grid-column: 2 / -1; position: relative; pointer-events: none; z-index: 1; }
.band { position: absolute; left: 0; right: 0; background: var(--band); border-top: 1px dashed var(--accent); border-bottom: 1px dashed var(--accent); }
.nowLine { position: absolute; left: 0; right: 0; height: 2px; background: var(--clash); z-index: 5; }
.nowLine::before { content: "now"; position: absolute; left: 4px; top: 1px; font-size: 10px; font-weight: 700; color: #fff; background: var(--clash); padding: 0 4px; border-radius: 3px; transform: translateY(-50%); }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.85) contrast(.9); }
}
:root[data-theme="dark"] .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.85) contrast(.9); }

.set {
  --c: var(--muted);
  position: absolute; left: 3px; right: 3px; z-index: 2;
  border: 0; border-left: 3px solid var(--c); border-radius: 5px;
  background: color-mix(in srgb, var(--c) 14%, var(--surface));
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--c) 25%, transparent);
  padding: 3px 6px; text-align: left; cursor: pointer; overflow: hidden;
  display: flex; flex-direction: column; gap: 1px;
  transition: opacity .12s, transform .12s;
}
.set:hover { z-index: 4; box-shadow: 0 0 0 1px var(--c), var(--shadow); }
.set .tm { font-size: 10.5px; color: var(--muted); font-variant-numeric: tabular-nums; line-height: 1.2; white-space: nowrap; }
.set .nm { font-size: 12.5px; font-weight: 600; line-height: 1.2; overflow-wrap: anywhere; }
.set .pj { font-size: 10.5px; color: var(--c); font-weight: 600; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; filter: brightness(.85); }
.set.tiny { padding-top: 1px; padding-bottom: 1px; }
.set.tiny .tm, .set.tiny .pj { display: none; }
.set.tiny .nm { font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.set.starred { box-shadow: 0 0 0 2px var(--star); }
.set.starred::after { content: "★"; position: absolute; top: 2px; right: 4px; color: var(--star); font-size: 12px; }
.set.starclash { box-shadow: 0 0 0 2px var(--clash); }
.set.starclash::after { content: "★!"; color: var(--clash); font-weight: 700; }

.grid.selecting .set { opacity: .28; }
.grid.selecting .set.overlap { opacity: 1; box-shadow: 0 0 0 2px var(--clash); }
.grid.selecting .set.sel { opacity: 1; box-shadow: 0 0 0 2px var(--accent), var(--shadow); z-index: 5; }

/* ---------- details sheet ---------- */
.sheet {
  position: fixed; z-index: 60; left: 50%; bottom: 16px; transform: translateX(-50%);
  width: min(560px, calc(100vw - 32px));
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line-strong); border-radius: 14px; box-shadow: var(--shadow);
  padding: 14px 16px 12px;
  max-height: 55dvh; overflow: auto;
}
.sheet h3 { margin: 0 32px 2px 0; font: 700 18px/1.25 "Space Grotesk", Inter, sans-serif; }
.sheet .meta { color: var(--muted); font-size: 13px; }
.sheet .meta b { color: var(--text); font-weight: 600; }
.sheet .actions { display: flex; gap: 8px; margin: 10px 0 6px; flex-wrap: wrap; }
.sheet .actions a, .sheet .actions button {
  border: 1px solid var(--line-strong); border-radius: 8px; padding: 5px 10px; background: transparent; cursor: pointer; text-decoration: none; font-size: 13px;
}
.sheet .actions .starBtn.on { background: var(--star); border-color: var(--star); color: #1d1b19; font-weight: 600; }
.sheet .close { position: absolute; top: 8px; right: 8px; border: 0; background: transparent; font-size: 20px; cursor: pointer; color: var(--muted); width: 32px; height: 32px; }
.sheet h4 { margin: 8px 0 4px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--clash); }
.sheet ul { margin: 0; padding: 0; list-style: none; font-size: 13px; display: grid; gap: 3px; }
.sheet li { cursor: pointer; }
.sheet li .t { color: var(--muted); font-variant-numeric: tabular-nums; margin-right: 6px; }
.sheet li .v { color: var(--muted); font-size: 12px; }
.sheet li.star::before { content: "★ "; color: var(--star); }

.foot { flex: none; padding: 5px 16px; color: var(--muted); font-size: 11px; border-top: 1px solid var(--line); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.foot a { color: var(--muted); }
