/* opo — Windows 95 flavoured UI over a dark map */
:root {
  --face: #c0c0c0;
  --face-lt: #dfdfdf;
  --face-hi: #ffffff;
  --face-dk: #808080;
  --face-xdk: #0a0a0a;
  --navy: #000080;
  --navy2: #1084d0;
  --mapbg: #0a0a12;
  --hot0: #f59e0b;
  --hot1: #f97316;
  --hot2: #ef4444;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --font: Tahoma, 'MS Sans Serif', Geneva, Verdana, 'Segoe UI', system-ui, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  overscroll-behavior: none;
  background: var(--mapbg);
  font-family: var(--font);
  font-size: 13px;
}

body {
  height: 100dvh;
  overflow: hidden;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  color: #000;
}

#map {
  position: absolute;
  inset: 0;
  background: #0d1018;
}

/* W95 bevel helpers */
.bevel-out { box-shadow: inset -1px -1px 0 var(--face-xdk), inset 1px 1px 0 var(--face-hi), inset -2px -2px 0 var(--face-dk), inset 2px 2px 0 var(--face-lt); }
.bevel-in  { box-shadow: inset -1px -1px 0 var(--face-hi), inset 1px 1px 0 var(--face-xdk), inset -2px -2px 0 var(--face-lt), inset 2px 2px 0 var(--face-dk); }
.bevel-thin-out { box-shadow: inset -1px -1px 0 var(--face-xdk), inset 1px 1px 0 var(--face-hi); }
.bevel-thin-in  { box-shadow: inset -1px -1px 0 var(--face-hi), inset 1px 1px 0 var(--face-xdk); }

/* ---------- attribution ---------- */
.maplibregl-ctrl-attrib {
  font-size: 9px !important;
  font-family: var(--font);
  background: rgba(10, 10, 18, 0.7) !important;
  color: #9aa1b8 !important;
  border-radius: 0 !important;
}
.maplibregl-ctrl-attrib a { color: #c6cbe0 !important; }
.maplibregl-ctrl-bottom-right { right: var(--sar); bottom: calc(var(--sab) + 34px); }

/* ---------- taskbar ---------- */
#taskbar {
  position: absolute;
  left: 0; right: 0;
  bottom: 0;
  z-index: 25;
  background: var(--face);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px max(12px, var(--sar)) calc(4px + var(--sab)) max(8px, var(--sal));
  min-height: calc(34px + var(--sab));
  box-shadow: inset 0 1px 0 var(--face-lt);
  border-top: 1px solid var(--face-hi);
}
.tb-btn {
  height: 26px;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--face);
  border: none;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 700;
  padding: 0 10px;
  cursor: pointer;
  color: #000;
  white-space: nowrap;
}
.tb-btn svg { display: block; }
.tb-btn:active, .tb-btn.pressed { box-shadow: inset -1px -1px 0 var(--face-hi), inset 1px 1px 0 var(--face-xdk), inset -2px -2px 0 var(--face-lt), inset 2px 2px 0 var(--face-dk); }
.tb-item {
  height: 26px;
  flex: 0 1 auto;
  min-width: 0;
  display: inline-flex;
  align-items: center;
  font-size: 12px;
  color: #000;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 8px;
}
.tb-sep { width: 2px; height: 20px; flex: 0 0 auto; box-shadow: inset 1px 0 0 var(--face-xdk), inset -1px 0 0 var(--face-hi); margin: 0 2px; }
#tb-spacer { flex: 1 1 auto; }
.tb-gps { cursor: pointer; font-size: 12px; font-weight: 700; position: relative; }
.tb-clock { font-size: 12px; }

/* gate: show a busy cursor while waiting for a GPS fix */
.gate.waiting .win-body { cursor: progress; }
.gate.waiting .gate-dots::after {
  content: '';
  display: inline-block;
  width: 8px;
  overflow: hidden;
  vertical-align: bottom;
  animation: waitdots 1.2s steps(4, end) infinite;
}
@keyframes waitdots { 0% { width: 0; } 100% { width: 24px; } }

/* ---------- generic windows ---------- */
#w95root {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 30;
}
.win {
  position: fixed;
  pointer-events: auto;
  background: var(--face);
  box-shadow: inset -1px -1px 0 var(--face-xdk), inset 1px 1px 0 var(--face-hi), inset -2px -2px 0 var(--face-dk), inset 2px 2px 0 var(--face-lt), 6px 6px 0 rgba(0, 0, 0, 0.35);
  font-family: var(--font);
  color: #000;
  max-width: calc(100vw - 12px);
}
.win-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  height: 21px;
  background: linear-gradient(90deg, var(--navy), var(--navy2));
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  padding: 0 3px 0 6px;
  cursor: default;
  white-space: nowrap;
  overflow: hidden;
}
.win-title .t { overflow: hidden; text-overflow: ellipsis; }
.win-x {
  flex: 0 0 auto;
  width: 17px; height: 15px;
  background: var(--face);
  border: none;
  font-size: 10px;
  line-height: 1;
  font-weight: 700;
  color: #000;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font);
}
.win-x:active { box-shadow: inset 1px 1px 0 var(--face-xdk); }
.win-body { padding: 12px 14px 14px; font-size: 12px; line-height: 1.5; }
.win-body p { margin-bottom: 8px; }
.win-body p:last-child { margin-bottom: 0; }
.win-body .muted { color: #333; }
.win-btns {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}
.win-btns:empty { display: none; }

.w95btn {
  background: var(--face);
  border: none;
  font-family: var(--font);
  font-size: 12px;
  color: #000;
  padding: 4px 14px;
  cursor: pointer;
  min-width: 60px;
  min-height: 26px;
}
.w95btn:active, .w95btn.pressed { box-shadow: inset -1px -1px 0 var(--face-hi), inset 1px 1px 0 var(--face-xdk), inset -2px -2px 0 var(--face-lt), inset 2px 2px 0 var(--face-dk); }
.w95btn.primary {
  background: linear-gradient(90deg, var(--navy), var(--navy2));
  color: #fff;
  font-weight: 700;
}
.w95btn:disabled { color: #808080; text-shadow: 1px 1px 0 #fff; cursor: default; }
.w95btn:focus-visible, .win-x:focus-visible, .tb-btn:focus-visible { outline: 1px dotted #000; outline-offset: -4px; }
.statrow { display: flex; gap: 10px; margin: 4px 0 10px; }
.stat { flex: 1; text-align: center; padding: 6px 2px; }
.stat .v { display: block; font-weight: 700; font-size: 16px; font-variant-numeric: tabular-nums; }
.stat .k { display: block; font-size: 10px; color: #222; margin-top: 2px; }

/* ---------- map controls (top-right) ---------- */
.ctrls {
  position: absolute;
  top: calc(var(--sat) + 10px);
  right: calc(var(--sar) + 10px);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  z-index: 15;
}
.mapbtn {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--face);
  border: none;
  font-family: var(--font);
  font-size: 11px;
  font-weight: 700;
  color: #000;
  padding: 4px 9px;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
  white-space: nowrap;
}
.mapbtn svg { display: block; }
.mapbtn:active { box-shadow: inset 1px 1px 0 var(--face-xdk), 0 1px 2px rgba(0, 0, 0, 0.4); }
.mapbtn:disabled { color: #808080; text-shadow: 1px 1px 0 #fff; }

/* desktop tooltips */
@media (hover: hover) {
  .mapbtn[data-tip]:hover::after, .tb-gps[data-tip]:hover::after {
    content: attr(data-tip);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background: #ffffe1;
    border: 1px solid #000;
    box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.5);
    color: #000;
    font-size: 11px;
    font-weight: 400;
    padding: 2px 6px;
    white-space: nowrap;
    z-index: 60;
    pointer-events: none;
  }
  .tb-gps { position: relative; }
}

/* ---------- legend ---------- */
.legend {
  position: absolute;
  left: calc(var(--sal) + 10px);
  bottom: calc(var(--sab) + 38px);
  z-index: 12;
  background: var(--face);
  color: #000;
  padding: 6px 8px;
  display: none;
  flex-direction: column;
  gap: 4px;
  font-size: 9px;
  box-shadow: inset -1px -1px 0 var(--face-xdk), inset 1px 1px 0 var(--face-hi), 2px 2px 0 rgba(0, 0, 0, 0.35);
}
.legend .bar { width: 96px; height: 7px; background: linear-gradient(90deg, #b45309, var(--hot0), var(--hot1), var(--hot2), #fde68a); }
.legend .row { display: flex; justify-content: space-between; }

/* ---------- you marker ---------- */
.you-wrap { position: relative; width: 0; height: 0; }
.you-dot {
  width: 13px; height: 13px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #000;
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.9);
}
.you-wrap::before {
  content: '';
  position: absolute;
  left: -17px; top: -17px;
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 2px solid rgba(239, 68, 68, 0.7);
  animation: youpulse 2s ease-out infinite;
}
.you-wrap.hidden { display: none; }
@keyframes youpulse {
  0% { transform: scale(0.35); opacity: 1; }
  100% { transform: scale(1.3); opacity: 0; }
}

/* ---------- venue popups (W95 windows on the map) ---------- */
.maplibregl-popup.w95 .maplibregl-popup-content {
  background: transparent;
  padding: 0;
  box-shadow: none;
  border-radius: 0;
  font-family: var(--font);
  font-size: 12px;
  color: #000;
}
.maplibregl-popup.w95 .maplibregl-popup-tip { border: none; }
.maplibregl-popup.w95.maplibregl-popup-anchor-bottom .maplibregl-popup-tip { border-top: 10px solid var(--face); }
.maplibregl-popup.w95.maplibregl-popup-anchor-top .maplibregl-popup-tip { border-bottom: 10px solid var(--face); }
.maplibregl-popup.w95.maplibregl-popup-anchor-left .maplibregl-popup-tip { border-right: 10px solid var(--face); }
.maplibregl-popup.w95.maplibregl-popup-anchor-right .maplibregl-popup-tip { border-left: 10px solid var(--face); }
.p-win {
  background: var(--face);
  box-shadow: inset -1px -1px 0 var(--face-xdk), inset 1px 1px 0 var(--face-hi), inset -2px -2px 0 var(--face-dk), inset 2px 2px 0 var(--face-lt);
  min-width: 190px;
  max-width: 240px;
}
.p-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  height: 20px;
  background: linear-gradient(90deg, var(--navy), var(--navy2));
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 0 3px 0 6px;
}
.p-head .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p-x {
  width: 16px; height: 14px;
  background: var(--face);
  border: none;
  font-size: 9px;
  line-height: 1;
  color: #000;
  cursor: pointer;
  font-family: var(--font);
  display: flex; align-items: center; justify-content: center;
}
.p-body { padding: 8px 10px 10px; font-size: 12px; }
.p-kind { color: #000; }
.p-crowd { font-weight: 700; margin-top: 5px; font-variant-numeric: tabular-nums; }
.p-crowd.live { color: #b91c1c; }
.p-tipbody { padding: 4px 8px; font-size: 11px; background: var(--face); box-shadow: inset -1px -1px 0 var(--face-xdk), inset 1px 1px 0 var(--face-hi); white-space: nowrap; }
.p-tipbody b { font-weight: 700; }
.p-tipbody .h { color: #b91c1c; font-weight: 700; }

/* ---------- toast ---------- */
.toast {
  position: absolute;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  bottom: calc(var(--sab) + 36px);
  z-index: 45;
  background: var(--face);
  color: #000;
  font-size: 12px;
  font-family: var(--font);
  padding: 7px 14px;
  box-shadow: inset -1px -1px 0 var(--face-xdk), inset 1px 1px 0 var(--face-hi), inset -2px -2px 0 var(--face-dk), inset 2px 2px 0 var(--face-lt), 3px 3px 0 rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  max-width: 86vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: #ffd2d2; }
.toast.error::before { content: '! '; font-weight: 700; }

.loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  justify-content: center;
  background: var(--mapbg);
  z-index: 5;
  transition: opacity 0.4s ease;
}
.loading.hide { opacity: 0; pointer-events: none; }
.loading .box {
  background: var(--face);
  color: #000;
  font-size: 13px;
  font-weight: 700;
  font-family: var(--font);
  padding: 14px 22px;
  display: flex;
  align-items: center;
  gap: 10px;
}
@keyframes blink { 50% { opacity: 0; } }
.loading .cursor { width: 7px; height: 13px; background: #000; animation: blink 1s steps(1) infinite; }

/* ---------- location gate (viewing requires location) ---------- */
.gate {
  position: absolute;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0a0a12;
  padding: 12px;
}
.gate.hidden { display: none; }
.gate .gwin {
  position: relative;
  width: min(360px, calc(100vw - 24px));
  box-shadow: inset -1px -1px 0 var(--face-xdk), inset 1px 1px 0 var(--face-hi), inset -2px -2px 0 var(--face-dk), inset 2px 2px 0 var(--face-lt), 6px 6px 0 rgba(0, 0, 0, 0.6);
}
.gate .win-body p { font-size: 13px; }
#gateBtn.hidden { display: none; }
#gateBtn { min-width: 120px; }

/* ---------- leaflet renderer ---------- */
#map { isolation: isolate; background: #0d1018; }
html, body { touch-action: auto; }
.leaflet-container {
  background: #0d1018;
  font-family: var(--font);
  outline: none;
  -webkit-user-select: none;
}
.leaflet-container .leaflet-interactive { cursor: pointer; }
.leaflet-control-attribution {
  background: rgba(10, 10, 18, 0.72) !important;
  color: #9aa1b8 !important;
  font-size: 10px !important;
}
.leaflet-control-attribution a { color: #c6cbe0 !important; }
.leaflet-bottom.leaflet-right { bottom: calc(38px + var(--sab)) !important; right: var(--sar); }

/* dark tiles via CSS inversion (OSM fallback stage) */
.tiles-invert { filter: invert(1) hue-rotate(180deg) brightness(0.95) contrast(0.9) saturate(0.8); }

/* W95 venue popup inside leaflet */
.leaflet-popup.w95 .leaflet-popup-content-wrapper {
  background: transparent;
  box-shadow: none;
  border-radius: 0;
  padding: 0;
  color: #000;
  font-family: var(--font);
}
.leaflet-popup.w95 .leaflet-popup-content { margin: 0; width: auto !important; }
.leaflet-popup.w95 .leaflet-popup-tip { display: none; }
.leaflet-popup.w95 .leaflet-popup-close-button { display: none; }

/* W95 tooltip */
.leaflet-tooltip.w95-tip {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
  font-family: var(--font);
}
.leaflet-tooltip.w95-tip::before { display: none; }

/* you marker (leaflet divIcon) */
.you-marker { width: 0; height: 0; }
.you-marker .you-dot {
  position: absolute;
  left: -7px; top: -7px;
  width: 13px; height: 13px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #000;
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.9);
}
.you-marker .you-ring {
  position: absolute;
  left: -18px; top: -18px;
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 2px solid rgba(239, 68, 68, 0.7);
  animation: youpulse 2s ease-out infinite;
}

/* bar photo in venue popup */
.leaflet-popup.w95 .leaflet-popup-content { min-width: 210px; }
.p-imgwrap {
  margin: -8px -10px 9px;
  border-bottom: 1px solid var(--face-xdk);
  background: var(--face-dk);
  overflow: hidden;
}
.p-img {
  display: block;
  width: 100%;
  height: 104px;
  object-fit: cover;
}
