/* RUN (Payphone Tag Runs) - built for one device: iPhone 17 Pro Max.
   Screen: 6.9", 2868 x 1320 px at 460 ppi, 3x  ->  440 x 956 points upright, 956 x 440 turned sideways.
   Upright: map on top, panel at the bottom. Sideways: map on the left, panel on the right.
   Safe areas come from the phone itself (env(): Dynamic Island at the top, home indicator at the bottom).
   Type follows iOS sizes (17 pt body); every control is at least 44 pt tall to tap. */
:root {
  --ink: #14233a;
  --muted: #5d6c84;
  --line: rgba(20, 35, 58, .12);
  --blue: #0d6efd;
  --blue-deep: #0d4aa8;
  --unowned: #8fd0f2;
  --raided: #e03c3c;
  --owned: #7b3fb8;
  --glass: rgba(255, 255, 255, .8);
  --pad: 16px;                    /* side margin on a 440 pt screen */
  --sheet-h: 56dvh;               /* panel: about 535 of 956 pt, map gets the rest */
  --tap: 44px;                    /* Apple's minimum tap size */
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  height: 100dvh; display: flex; flex-direction: column; overflow: hidden;
  font: 17px/1.35 -apple-system, "SF Pro Text", system-ui, sans-serif; color: var(--ink); background: #dfe8f3;
  -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent;
}
button, a { touch-action: manipulation; }

/* ---------- Map (top part of the screen) ---------- */
#mapwrap { position: relative; flex: 1 1 auto; min-height: 0; }
#map { position: absolute; inset: 0; overflow: hidden; }
#fab {
  position: absolute; right: var(--pad); bottom: calc(14px + env(safe-area-inset-bottom, 0px)); z-index: 1000;
  width: 56px; height: 56px; padding: 0; border-radius: 28px; display: grid; place-items: center; color: #fff; border: 0;
  background: linear-gradient(180deg, #5db0ff 0%, #0d6efd 55%, #0b4fc2 100%);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.6), 0 3px 10px rgba(8, 40, 110, .4);
}
body:not(.hide-sheet) #fab { display: none; }        /* while the panel is open, its own arrow closes it */
#locate {
  position: absolute; right: var(--pad); top: calc(8px + env(safe-area-inset-top, 0px)); z-index: 1000;
  width: 48px; height: 48px; border-radius: 24px; font-size: 24px; color: var(--ink); border: 1px solid var(--line);
  background: var(--glass); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
/* lit (blue) while the map is centred on you and following */
#locate.on { color: #fff; border-color: transparent; background: linear-gradient(180deg, #5db0ff 0%, #0d6efd 55%, #0b4fc2 100%); box-shadow: inset 0 1px 0 rgba(255,255,255,.6), 0 2px 8px rgba(8, 40, 110, .4); }
#pickHint {
  position: absolute; left: calc(var(--pad) + env(safe-area-inset-left, 0px)); right: 76px; top: calc(8px + env(safe-area-inset-top, 0px)); z-index: 1000;
  min-height: 48px; display: flex; align-items: center; padding: 8px 16px; border-radius: 24px; font-size: 15px; font-weight: 600;
  background: var(--glass); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
#pickHint[hidden] { display: none; }
.end-flag { font-size: 30px; line-height: 1; }
/* route stop number, centred on its red circle (15 to 30 pt across, set by the zoom in app.js) */
#map { --pin-d: 30px; }
.stopnum {
  position: absolute; left: 0; top: 0; transform: translate(-50%, -50%);
  width: var(--pin-d); height: var(--pin-d); display: grid; place-items: center; pointer-events: none;
  font: 700 max(10px, calc(var(--pin-d) / 2))/1 -apple-system, system-ui, sans-serif; color: #fff; text-shadow: 0 1px 1px rgba(0,0,0,.45);
}
.mid-flag { font-size: 28px; line-height: 1; }

/* ---------- Panel (bottom sheet) ---------- */
#sheet {
  flex: none; height: min(var(--sheet-h), calc(100dvh - 100px)); display: flex; flex-direction: column; min-height: 0;
  background: var(--glass); -webkit-backdrop-filter: blur(22px) saturate(1.4); backdrop-filter: blur(22px) saturate(1.4);
  border-top: 1px solid var(--line); border-radius: 24px 24px 0 0; box-shadow: 0 -4px 18px rgba(0,0,0,.18);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
body.hide-sheet #sheet { display: none; }
#sheet { position: relative; }
#grip { flex: none; height: 40px; display: flex; align-items: center; justify-content: center; touch-action: none; cursor: ns-resize; position: relative; }
#grip .bar { width: 44px; height: 5px; border-radius: 3px; background: rgba(20, 35, 58, .28); }
#minimise { position: absolute; left: calc(50% + 30px); top: 0; width: var(--tap); height: 40px; border: 0; background: none; color: var(--muted); display: grid; place-items: center; padding: 0; }   /* right beside the grab bar */
body.resizing, body.resizing * { user-select: none; -webkit-user-select: none; }
#sheet header { padding: 0 8px 4px var(--pad); display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
#sheet h1 { font-size: 22px; line-height: 1.2; margin: 0; }
#status { margin: 2px 0 0; font-size: 14px; color: var(--muted); }
#cog { flex: none; width: var(--tap); height: var(--tap); border: 0; border-radius: 22px; background: transparent; color: var(--ink); display: grid; place-items: center; }
#cog svg { width: 24px; height: 24px; }
#cog.on { background: rgba(13, 110, 253, .16); color: var(--blue-deep); }

#tabs { display: flex; gap: 2px; padding: 6px 8px 8px; overflow-x: auto; scrollbar-width: none; }
#tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 1 0 auto; min-height: var(--tap); display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  font: inherit; font-size: 15px; white-space: nowrap; padding: 0 8px; border-radius: 20px; border: 0; background: transparent; color: var(--ink);
}
.tab.on { background: rgba(13, 110, 253, .16); font-weight: 600; }
.tab .n { color: var(--muted); font-weight: 400; }
.dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; border: 1px solid rgba(0,0,0,.25); }
.c0 { background: var(--unowned); } .c1 { background: var(--raided); } .c2 { background: var(--owned); }

#sortArea { padding: 4px var(--pad) 10px; border-top: 1px solid var(--line); display: none; }
.seg { display: flex; align-items: center; gap: 10px; margin-top: 6px; font-size: 15px; color: var(--muted); }
.seg .group { flex: 1; display: flex; background: rgba(20,35,58,.08); border-radius: 10px; padding: 2px; }
.seg button { flex: 1; min-height: 40px; font: inherit; font-size: 15px; border: 0; border-radius: 8px; background: transparent; color: var(--ink); }
.seg button.on { background: #fff; font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.routeopts { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 8px; font-size: 15px; color: var(--muted); }
.chip { min-height: 40px; font: inherit; font-size: 15px; padding: 0 13px; border: 1px solid var(--line); border-radius: 18px; background: rgba(255,255,255,.75); color: var(--ink); }
.chip.on { background: var(--blue); border-color: var(--blue); color: #fff; }
.routemsg { margin: 6px 0 0; font-size: 14px; color: var(--ink); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
#sortArea.route .routeopts { flex-wrap: nowrap; gap: 6px; }
#sortArea.route .chip { padding: 0 11px; white-space: nowrap; }

#list { flex: 1; min-height: 0; overflow-y: auto; margin: 0; padding: 0; list-style: none; -webkit-overflow-scrolling: touch; border-top: 1px solid var(--line); }
#list li { min-height: 64px; padding: 10px 8px 10px var(--pad); border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: center; }
#list .txt { flex: 1; min-width: 0; cursor: pointer; }
#list .txt b { display: block; font-size: 17px; }
#list .sub { color: var(--muted); font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#list .dist { font-weight: 400; font-size: 13px; color: var(--muted); }
#list .btns { display: flex; gap: 2px; align-items: center; flex: none; }
button.small, a.small {
  display: inline-flex; align-items: center; gap: 4px; min-height: var(--tap); padding: 0 14px; font: inherit; font-size: 15px;
  border: 1px solid var(--line); border-radius: 22px; background: rgba(255,255,255,.85); color: var(--blue-deep); text-decoration: none; white-space: nowrap;
}
button.x { width: var(--tap); height: var(--tap); border: 0; background: none; font-size: 26px; line-height: 1; color: var(--muted); padding: 0; }
button.own { width: var(--tap); height: var(--tap); flex: none; border: 0; border-radius: 50%; background: var(--owned); color: #fff; font-size: 21px; line-height: 1; }
#list li.more { display: block; min-height: 0; color: var(--muted); font-size: 14px; text-align: center; }
li.midrow { background: rgba(13, 110, 253, .07); }
li.midrow .midicon { width: var(--tap); flex: none; text-align: center; font-size: 24px; }
/* Route tab: ticks, select all, drag to reorder */
label.tick { width: 36px; height: var(--tap); flex: none; display: grid; place-items: center; margin-right: -4px; cursor: pointer; }
label.tick input { width: 24px; height: 24px; margin: 0; accent-color: var(--blue); cursor: pointer; }
#list li.selall { min-height: 44px; padding-top: 0; padding-bottom: 0; background: rgba(13, 110, 253, .05); }
#list li.selall .txt b { font-size: 16px; }
#list li.off .txt { opacity: .5; }
#list li[data-id] { gap: 8px; }
button.drag { width: 40px; height: var(--tap); flex: none; border: 0; background: none; color: var(--muted); font-size: 28px; line-height: 1; padding: 0; touch-action: none; cursor: grab; }
#list li.dragging { background: #fff; box-shadow: 0 6px 18px rgba(0,0,0,.22); position: relative; z-index: 2; }
#list li.dragging button.drag { cursor: grabbing; color: var(--blue); }
button.btn.on { border-color: var(--blue); color: var(--blue-deep); background: rgba(13, 110, 253, .12); }
#empty { margin: 0; padding: var(--pad); color: var(--muted); font-size: 15px; }

#actions { padding: 10px var(--pad); border-top: 1px solid var(--line); display: grid; gap: 8px; }
#actions:empty { display: none; }
.row { display: flex; gap: 8px; }
button.btn {
  flex: 1; min-height: 50px; font: inherit; font-size: 17px; padding: 0 10px; border-radius: 14px; border: 1px solid var(--line);
  background: rgba(255,255,255,.88); color: var(--ink);
}
button.btn.primary { color: #fff; border: 0; font-weight: 600; background: linear-gradient(180deg, #5db0ff 0%, #0d6efd 55%, #0b4fc2 100%); box-shadow: inset 0 1px 0 rgba(255,255,255,.6); }
button.btn.danger { color: #c0262d; }
button.btn.icon { flex: 0 0 56px; padding: 0; display: grid; place-items: center; }
button:disabled { opacity: .45; }
.msg { font-size: 14px; color: #1b7a3d; min-height: 18px; }

/* ---------- Settings pane ---------- */
#settings { flex: 1; overflow-y: auto; padding: 0 var(--pad) var(--pad); display: none; border-top: 1px solid var(--line); -webkit-overflow-scrolling: touch; }
#settings section { padding: 14px 0; border-bottom: 1px solid var(--line); display: grid; gap: 10px; }
#settings h2 { font-size: 17px; margin: 0; }
#settings p { margin: 0; font-size: 15px; color: var(--muted); line-height: 1.4; }
.setHead { display: flex; align-items: center; justify-content: space-between; padding: 10px 0 4px; }
.setHead h2 { font-size: 20px !important; }
.statechips { display: flex; flex-wrap: wrap; gap: 8px; }
.zoomhead { display: flex; align-items: baseline; justify-content: space-between; }
.zoomval { font-size: 17px; font-weight: 600; color: var(--blue-deep); font-variant-numeric: tabular-nums; }
.zoomrow { display: flex; align-items: center; gap: 10px; }
.zoomrow .lbl { font-size: 13px; color: var(--muted); flex: none; }
.zoomrow input[type=range] { flex: 1; min-width: 0; height: var(--tap); margin: 0; accent-color: var(--blue); touch-action: pan-y; }
.zoomset .chip { justify-self: start; }

/* ---------- Suggested locations pane ---------- */
#suggest { display: none; flex: 1; min-height: 0; flex-direction: column; border-top: 1px solid var(--line); }
#suggest .setHead { padding: 10px var(--pad) 4px; }
#suggest .setHead h2 { margin: 0; }
#suggest .pad { padding: 0 var(--pad); }
#suggest .routeopts { margin: 4px 0 0; }
#suggest ul { flex: 1; min-height: 0; overflow-y: auto; margin: 8px 0 0; padding: 0; list-style: none; border-top: 1px solid var(--line); -webkit-overflow-scrolling: touch; }
#suggest li.sg { min-height: 64px; display: flex; gap: 12px; align-items: center; padding: 10px var(--pad); border-bottom: 1px solid var(--line); cursor: pointer; }
#suggest li.sg.on { background: rgba(13, 110, 253, .1); }
#suggest .tick { flex: none; width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--muted); display: grid; place-items: center; color: #fff; font-size: 16px; line-height: 1; }
#suggest li.sg.on .tick { background: var(--blue); border-color: var(--blue); }
#suggest .txt { flex: 1; min-width: 0; }
#suggest .txt b { display: block; font-size: 17px; }
#suggest .sub { color: var(--muted); font-size: 15px; }
#suggest .dist { font-weight: 400; font-size: 13px; color: var(--muted); }
#suggest .sgfoot { padding: 10px var(--pad); border-top: 1px solid var(--line); }
#suggest .sgfoot button.btn { width: 100%; }

/* ---------- Location banner (over the map, under the Dynamic Island) ---------- */
#locBanner {
  position: absolute; left: var(--pad); right: 76px; top: calc(8px + env(safe-area-inset-top, 0px)); z-index: 1001;
  display: flex; gap: 10px; align-items: flex-start; padding: 12px; border-radius: 16px; font-size: 15px; line-height: 1.35;
  background: var(--glass); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); box-shadow: 0 3px 14px rgba(0,0,0,.22);
  flex-wrap: wrap;
}
#locBanner[hidden] { display: none; }
#locBanner p { margin: 0; flex: 1 1 200px; }
#locBanner .ico { font-size: 22px; line-height: 1.1; }
#locBanner .acts { display: flex; gap: 8px; flex: 1 1 100%; }
#locBanner .acts .chip { flex: 1; min-height: var(--tap); }

/* ---------- Splash page (first run) ---------- */
#splash {
  position: fixed; inset: 0; z-index: 3000; overflow-y: auto; -webkit-overflow-scrolling: touch;
  display: flex; align-items: center; justify-content: center;
  padding: calc(16px + env(safe-area-inset-top, 0px)) var(--pad) calc(16px + env(safe-area-inset-bottom, 0px));
  background: radial-gradient(120% 80% at 50% 0%, #6cc4ff 0%, #1673eb 45%, #062a96 100%);
}
#splash[hidden] { display: none; }
#splash .card {
  width: 100%; max-width: 440px; margin: auto; padding: 28px 22px 20px; border-radius: 28px; text-align: center;
  background: rgba(255, 255, 255, .92); -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  box-shadow: 0 10px 40px rgba(2, 20, 80, .45); color: #14233a;
}
#splash .logo { width: 84px; height: 84px; border-radius: 20px; box-shadow: 0 4px 14px rgba(0,0,0,.25); }
#splash h1 { font-size: 28px; margin: 14px 0 4px; }
#splash .lead { margin: 0 0 8px; color: #5d6c84; font-size: 17px; }
#splash section { text-align: left; padding: 16px 0; border-top: 1px solid rgba(20,35,58,.12); display: grid; gap: 10px; }
#splash p { margin: 0; font-size: 16px; line-height: 1.4; }
#splash .hint { font-size: 14px; color: #5d6c84; text-align: center; }
#splash button.big { width: 100%; min-height: 56px; font-size: 18px; border-radius: 16px; }

/* ---------- Landscape: iPhone 17 Pro Max turned sideways (956 x 440 pt) ---------- */
/* The Dynamic Island sits at the left or right edge, the home indicator along the bottom. */
@media (orientation: landscape) {
  :root { --side-w: 406px; }   /* 384 pt of content + the 22 pt handle strip */
  body { flex-direction: row; }
  #mapwrap { flex: 1 1 auto; min-width: 0; }
  #sheet {
    flex: none; width: min(calc(var(--side-w) + env(safe-area-inset-right, 0px)), calc(100vw - 200px)); height: 100dvh; padding-left: 22px;
    border-top: 0; border-left: 1px solid var(--line); border-radius: 22px 0 0 22px; box-shadow: -4px 0 18px rgba(0,0,0,.18);
    padding-right: env(safe-area-inset-right, 0px); padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  /* a little more compact so the list keeps room on the 440 pt height */
  #sheet header { padding: 8px 6px 2px 8px; }
  #grip { position: absolute; left: 0; top: 0; bottom: 0; width: 22px; height: auto; cursor: ew-resize; }
  #grip .bar { width: 5px; height: 44px; }
  #minimise { left: -11px; top: 4px; transform: rotate(-90deg); }   /* arrow points right, toward the screen edge */
  #sheet h1 { font-size: 19px; }
  #status { font-size: 13px; }
  #tabs { padding: 4px 6px 6px; }
  .tab { font-size: 14px; padding: 0 6px; }
  #sortArea { padding: 2px var(--pad) 8px; }
  #list li, #suggest li.sg { min-height: 56px; padding-top: 6px; padding-bottom: 6px; }
  #actions { padding: 8px var(--pad); }
  button.btn { min-height: 46px; }
  /* Route tab: the option chips flow together into two rows instead of three */
  #sortArea.route { display: flex !important; flex-wrap: wrap; align-items: center; gap: 6px; padding-top: 6px; }
  #sortArea.route .routeopts { display: inline-flex; flex-wrap: nowrap; align-items: center; gap: 6px; margin: 0; }   /* each label stays with its buttons */
  #sortArea.route .lbl { font-size: 13px; color: var(--muted); }
  #sortArea.route .routemsg { flex-basis: 100%; margin: 0; font-size: 13px; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
  #locate { top: 10px; }
  #pickHint, #locBanner { top: 10px; left: calc(var(--pad) + env(safe-area-inset-left, 0px)); }
  #fab { bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
  body.hide-sheet #fab, body.hide-sheet #locate { right: calc(var(--pad) + env(safe-area-inset-right, 0px)); }

}

/* ---------- Dark mode ---------- */
@media (prefers-color-scheme: dark) {
  #list li.dragging { background: #1c2533; }
  :root { --ink: #e8eef8; --muted: #9fb0c8; --line: rgba(255,255,255,.14); --glass: rgba(24, 34, 52, .82); }
  body { background: #0f1724; }
  .seg .group { background: rgba(255,255,255,.12); }
  .seg button.on { background: rgba(255,255,255,.22); }
  button.btn, button.small, a.small, .chip { background: rgba(255,255,255,.12); color: var(--ink); }
  a.small, button.small { color: #8fc0ff; }
  .chip.on { color: #fff; }
  #cog.on, .zoomval { color: #8fc0ff; }
  #grip .bar { background: rgba(255,255,255,.35); }
}
